﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DeviceManager.BusinessLogicLayer;
using DeviceManager.DataAccessLayer;

namespace DeviceManagementIT.DevicesManager.DevicesManagement
{
    public partial class frmGGroupDevice : DevExpress.XtraEditors.XtraForm
    {
        DeviceBllOperation devicebll = new DeviceBllOperation();
        THIETBI device;
        public frmGGroupDevice()
        {
            InitializeComponent();
        }

        private void btnAddDevice_Click(object sender, EventArgs e)
        {
            frmAddDevices adddevice = new frmAddDevices();
            adddevice.Show();
        }

        private void btnUpdateDevice_Click(object sender, EventArgs e)
        {
            frmComponents updatedevice = new frmComponents();
            updatedevice.Show();
        }

        private void btnLoadDevice_Click(object sender, EventArgs e)
        {
            device = new THIETBI();
            List<THIETBI> listdevice = devicebll.GetRecordDevice(device);
            grCListDevice.DataSource = listdevice;
        }
        private void btnDelDevice_Click(object sender, EventArgs e)
        {
            device = new THIETBI();
            if (grVListDevice.DataRowCount != 0)
            {
                device.ThietBiID = int.Parse(grVListDevice.GetFocusedRowCellDisplayText("ThietBiID"));
                string message = devicebll.DeleteRecordDevice(device);
                MessageBox.Show(message, "Message");
                btnLoadDevice.PerformClick();
            }
        }

        private void frmGGroupDevice_Load(object sender, EventArgs e)
        {
            CountryDbOperation m_CountryDbOperation = new CountryDbOperation();
            cbbSortDevice.Properties.DataSource = m_CountryDbOperation.GetRecord(new NUOC());
            cbbSortDevice.Properties.DisplayMember = "NuocID";
            cbbSortDevice.Properties.ValueMember = "NuocID";

            btnLoadDevice.PerformClick();
        }

        private void cbbSortDevice_SelectedIndexChanged(object sender, EventArgs e)
        {
            GGroupbllOperation m_ggroup = new GGroupbllOperation();
            int t = int.Parse(cbbSortDevice.EditValue.ToString());
            grCListDevice.DataSource = m_ggroup.SortGGroupID(new LOAITHIETBI(), int.Parse(cbbSortDevice.EditValue.ToString()));
        }

        private void txtSearchDevice_TextChanged(object sender, EventArgs e)
        {
            GGroupbllOperation m_ggroup = new GGroupbllOperation();
            string t = txtSearchDevice.EditValue.ToString();
            grCListDevice.DataSource = m_ggroup.SortGGroupName(new LOAITHIETBI(), t);
        }
    }
}